import axios from 'axios'



class Request {

    private _url: string = '';

    constructor(url: string, port?: number) {
        this._url = url;
        if (port) {
            this._url = `${url}:${port}`
        } else {
            this._url = `${url}`
        }
    }

    public async get(path: string, param ?: any) {
        if (param) {
            return axios.get(`${this._url}${path}` , {
                params: param
            });
        } else {
            return axios.get(`${this._url}${path}`);
        }
    }

    public async post(path: string, param?: any) {
        console.log(`url : ${this._url}${path} , param: ${JSON.stringify(param)}`)
        if (param) {
            param = JSON.stringify(param);
            return axios.post(`${this._url}${path}` , param , {
                headers: {
                    'Content-Type': 'application/json'
                }
            });
        } else {
            return axios.post(`${this._url}${path}`);
        }
    }

}

//codespace后端
// export default new Request("https://1807149205-congenial-lamp-7w667vj4vqrcgjw-8080.preview.app.github.dev");
export default new Request("http://127.0.0.1" , 8080);


